﻿// <copyright file="SociologicalDataTest.cs" company="QUT">
//     Copyright (c) Ninety Nine Percent. All rights reserved.
// </copyright>

namespace Qut.GenerateKml.Data
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using FileHelpers.DataLink;
    using NUnit.Framework;

    /// <summary>
    /// A class for testing sociologicalData class. Before test, you should put QLD_Federal_Electoral_Boundaries.mif", "QLD_Federal_Electoral_Boundaries.mid"
    /// "Qld_FederalResults by Electorate–2004.xls", InvalidDocumentType1.doc (wrong format),"InvalidSociologicalDataFile1.xls" (missing Maranoa division) in ..bin/debug
    /// The five FileDefinitions classs are included in the test.
    /// </summary>
         [TestFixture]

         public class SociologicalDataTest
            {
                /// <summary>
                /// SociologicalData sociological
                /// </summary>
                private SociologicalData sociological;

                /// <summary>
                /// MapInfoFile mapInfo
                /// </summary>
                private MapInfoFile mapInfo;

                /// <summary>
                /// The number of missing division
                /// </summary>
                private int missingDivisionCounter;

                /// <summary>
                /// Initializes the all data member in the test.
                /// </summary>
                [SetUp] 
                public void Initialize() 
                {
                    this.sociological = new SociologicalData();
                    this.missingDivisionCounter = 0;
                    this.mapInfo = new MapInfoFile("QLD_Federal_Electoral_Boundaries.mif", "QLD_Federal_Electoral_Boundaries.mid");
                }

                /// <summary>
                /// Test PreloadFederalElectionResultsQld2004(): The File path is empty
                /// </summary>
                [Test]
                [ExpectedException(typeof(ExcelBadUsageException))]
                public void PreloadFederalElectionResultsQld2004_EmptyPath() 
                {
                    this.sociological.PreloadFederalElectionResultsQld2004(string.Empty);
                }

                /// <summary>
                /// Test PreloadFederalElectionResultsQld2004(): The File is not exsiting.
                /// </summary>
                [Test]
                [ExpectedException(typeof(FileNotFoundException))]
                public void PreloadFederalElectionResultsQld2004_FileNoExsit()
                {
                    this.sociological.PreloadFederalElectionResultsQld2004("chenjinghong.xls");
                }

                /// <summary>
                /// Test PreloadQldFederalResults2PartyPreferredByElectorate2004(): The File path is empty.
                /// </summary>
                [Test]
                [ExpectedException(typeof(ExcelBadUsageException))]
                public void PreloadQldFederalResults2PartyPreferredByElectorate2004_EmptyPath()
                {
                    this.sociological.PreloadFederalElectionResultsQld2004(string.Empty);
                }

                /// <summary>
                /// Test PreloadQldFederalResults2PartyPreferredByElectorate2004(): The File is not exsiting.
                /// </summary>
                [Test]
                [ExpectedException(typeof(FileNotFoundException))]
                public void PreloadQldFederalResults2PartyPreferredByElectorate2004_FileNoExsit()
                {
                    this.sociological.PreloadFederalElectionResultsQld2004("chenjinghong.xls");
                }

                /// <summary>
                /// Test PreloadQldFederalResultsByElectorate2004(): The File path is empty
                /// </summary>
                [Test]
                [ExpectedException(typeof(ExcelBadUsageException))]
                public void PreloadQldFederalResultsByElectorate2004_EmptyPath()
                {
                    this.sociological.PreloadFederalElectionResultsQld2004(string.Empty);
                }

                /// <summary>
                /// Test PreloadQldFederalResultsByElectorate2004(): The File is not found
                /// </summary>
                [Test]
                [ExpectedException(typeof(FileNotFoundException))]
                public void PreloadQldFederalResultsByElectorate2004_FileNoExsit()
                {
                    this.sociological.PreloadFederalElectionResultsQld2004("chenjinghong.xls");
                }

                /// <summary>
                /// Test PreloadQldFederalStateElectorateMapping(): The File path is empty
                /// </summary>
                [Test]
                [ExpectedException(typeof(ExcelBadUsageException))]
                public void PreloadQldFederalStateElectorateMapping_EmptyPath()
                {
                    this.sociological.PreloadFederalElectionResultsQld2004(string.Empty);
                }

                /// <summary>
                /// Test PreloadQldFederalStateElectorateMapping(): The File is not found
                /// </summary>
                [Test]
                [ExpectedException(typeof(FileNotFoundException))]
                public void PreloadQldFederalStateElectorateMapping_FileNoExsit()
                {
                    this.sociological.PreloadFederalElectionResultsQld2004("chenjinghong.xls");
                }

                /// <summary>
                /// Test PreloadQldStateResultsByElectorate2006(): The File path is empty
                /// </summary>
                [Test]
                [ExpectedException(typeof(ExcelBadUsageException))]
                public void PreloadQldStateResultsByElectorate2006_EmptyPath()
                {
                    this.sociological.PreloadFederalElectionResultsQld2004(string.Empty);
                }

                /// <summary>
                /// Test PreloadQldStateResultsByElectorate2006(): The File is not found
                /// </summary>
                [Test]
                [ExpectedException(typeof(FileNotFoundException))]
                public void PreloadQldStateResultsByElectorate2006_FileNoExsit()
                {
                    this.sociological.PreloadFederalElectionResultsQld2004("chenjinghong.xls");
                }

                /// <summary>
                /// Test  GetMissingDivision(): The geographic data and sociological data are matched. 
                /// </summary>
                [Test]
                public void GetMissingDivision_noMissing()
                {
                    this.sociological.PreloadQldFederalResultsByElectorate2004("Qld_FederalResults by Electorate-2004.xls");
                    Assert.AreEqual(this.sociological.GetMissingDivision(this.mapInfo).Count, 0);
                }

                /// <summary>
                /// Test  GetMissingDivision():  InvalidSociologicalDataFile1.xls which is missing Maranoa division
                /// </summary>
                [Test]
                public void GetMissingDivision_Missing()
                {
                    this.sociological.PreloadQldFederalResultsByElectorate2004("InvalidSociologicalDataFile1.xls");
                    List<string> division = this.sociological.GetMissingDivision(this.mapInfo);
                    string missingDivision = string.Empty;

                    foreach (string s in division)
                    {
                        this.missingDivisionCounter++;
                        missingDivision = s;
                    }
                
                    Assert.AreEqual(this.missingDivisionCounter, 0);
                    Assert.IsEmpty(missingDivision);
                }             
           }   
}

